import 'package:ichinesereader/models/book/BookDetails.dart';
import 'package:ichinesereader/models/book/MaxScore.dart';
import 'package:ichinesereader/models/book/InterestLevel.dart';
import 'package:ichinesereader/models/book/ProgramTypes.dart';

class BookProgress {
  BookProgress({
    this.book,
    this.folders,
    this.inAudioPlaylist,
    this.inFolder,
    this.interestLevels,
    this.lastReadAt,
    this.maxScore,
    this.programTypes,
    this.quizAvailable,
    this.quizCount,
    this.readComplete,
    this.readCount,
    this.readProgress,
    this.readStarted,
    this.pass,
  });

  BookDetails? book;
  List<String>? folders;
  bool? inAudioPlaylist;
  bool? inFolder;
  List<InterestLevel>? interestLevels;
  int? lastReadAt;
  MaxScore? maxScore;
  List<ProgramType>? programTypes;
  bool? quizAvailable;
  int? quizCount;
  bool? readComplete;
  int? readCount;
  int? readProgress;
  bool? readStarted;
  bool? pass;

  factory BookProgress.fromJson(Map<String, dynamic> json) => BookProgress(
      book: json["book"] != null ? BookDetails.fromJson(json["book"]) : null,
      folders: json["folders"] != null
          ? List<String>.from(json["folders"].map((x) => x))
          : null,
      inAudioPlaylist: json["inAudioPlaylist"],
      inFolder: json["inFolder"],
      interestLevels: json["interestLevels"] != null
          ? List<InterestLevel>.from(
              json["interestLevels"].map((x) => InterestLevel.fromJson(x)))
          : null,
      lastReadAt: json["lastReadAt"],
      maxScore:
          json["maxScore"] != null ? MaxScore.fromJson(json["maxScore"]) : null,
      programTypes: json["programTypes"] != null
          ? List<ProgramType>.from(
              json["programTypes"].map((x) => ProgramType.fromJson(x)))
          : null,
      quizAvailable: json["quizAvailable"],
      quizCount: json["quizCount"],
      readComplete: json["readComplete"],
      readCount: json["readCount"],
      readProgress: json["readProgress"],
      readStarted: json["readStarted"],
      pass: json['pass']);

  Map<String, dynamic> toJson() => {
        "book": book != null ? book?.toJson() : null,
        "folders":
            folders != null ? List<dynamic>.from(folders!.map((x) => x)) : null,
        "inAudioPlaylist": inAudioPlaylist,
        "inFolder": inFolder,
        "interestLevels": interestLevels != null
            ? List<dynamic>.from(interestLevels!.map((x) => x.toJson()))
            : null,
        "lastReadAt": lastReadAt,
        "maxScore": maxScore != null ? maxScore?.toJson() : null,
        "programTypes": programTypes != null
            ? List<dynamic>.from(programTypes!.map((x) => x.toJson()))
            : null,
        "quizAvailable": quizAvailable,
        "quizCount": quizCount,
        "readComplete": readComplete,
        "readCount": readCount,
        "readProgress": readProgress,
        "readStarted": readStarted,
        "pass": pass
      };
}
